<?php
// +---------------------------------------------------------------------+
// | OneBase    | [ WE CAN DO IT JUST THINK ]                            |
// +---------------------------------------------------------------------+
// | Licensed   | http://www.apache.org/licenses/LICENSE-2.0 )           |
// +---------------------------------------------------------------------+
// | Author     | Bigotry <3162875@qq.com>                               |
// +---------------------------------------------------------------------+
// | Repository | https://gitee.com/Bigotry/OneBase                      |
// +---------------------------------------------------------------------+

namespace app\admin\logic;

/**
 * 倍投逻辑
 */
class DoubleThrow extends AdminBase
{
    
  
    
    /**
     * 获取倍投列表
     */
    public function getDoubleThrowList($where = [], $field = 'a.*', $order = '')
    {
        
        $this->modelPlanUserThrow->alias('a');
        
       
        $where['a.' . DATA_STATUS_NAME] = ['neq', DATA_DELETE];
        $where['a.is_user'] =1;
        $list=$this->modelPlanUserThrow->getList($where, $field, $order);
        $this->modelPlanUserThrow->alias('a');
        $count=$this->modelPlanUserThrow->where($where)->count();
        return ['list'=>$list,'count'=>$count];
    }
    
    /**
     * 获取倍投列表搜索条件
     */
    public function getWhere($data = [])
    {
        
        $where = [];
        
        !empty($data['search_data']) && $where['a.title'] = ['like', '%'.$data['search_data'].'%'];
        return $where;
    }
    
    /**
     * 倍投信息编辑
     */
    public function DoubleThrowEdit($data = [])
    {



        $url = url('ThrowList');
        $max_bureaus=0;
        foreach ($data['count'] as $k=>$v){
            $data['recharge'][$k]>$max_bureaus && $max_bureaus=$data['recharge'][$k];
            $arr=[
                'count'=>$v,
                'multiple'=>$data['recharge'][$k],
                'bureaus'=>$data['bureaus'][$k],
                'bureaus_two'=>$data['bureaus_two'][$k],
            ];
            $datas[]=$arr;
        }
        $data['plan_count']=count($data['count']);
        $data['content']=json_encode($datas);
        $data['is_user']=1;
        $data['max_multiple']=$max_bureaus;

        $result = $this->modelPlanUserThrow->setInfo($data);
        
        $handle_text = empty($data['id']) ? '新增' : '编辑';
        
        $result && action_log($handle_text, '倍投' . $handle_text . '，倍投名称：' . $data['title']);
        
        return $result ? [RESULT_SUCCESS, '倍投操作成功', $url] : [RESULT_ERROR, $this->modelPlanUserThrow->getError()];
    }

    /**
     * 获取倍投信息
     */
    public function getDoubleThrowInfo($where = [], $field = 'a.*')
    {
        
        $this->modelPlanUserThrow->alias('a');


        
        $where['a.' . DATA_STATUS_NAME] = ['neq', DATA_DELETE];
        

        
        return $this->modelPlanUserThrow->getInfo($where, $field);
    }


    /**
     * 倍投删除
     */
    public function update_info($where = [])
    {

        //dd($where);

        $result = $this->modelPlanUserThrow->setInfo($where);


        return $result ? [RESULT_SUCCESS, '操作成功'] : [RESULT_ERROR, '操作失败'];
    }
}
